package impl

import (
	"context"
	"gitee.com/76439984/vblog/tree/master/api/apps/user"
)

func (i *Impl) Login(ctx context.Context, req *user.LoginRequest) (*user.Session, error) {
	// 比对用户名和密码
	if err := i.Auth.Validate(req.Name, req.Pass); err != nil {
		return nil, err
	}
	// 记录一个session
	sess := i.createSession(req.Name)

	return user.NewSession(req.Name, sess), nil
}

func (i *Impl) Logout(ctx context.Context, req *user.LogoutRequest) error {
	i.deleteSession(req.Username)
	return nil
}
